package org.example.zixuansuo;

import java.util.concurrent.TimeUnit;

public class lockTest {
    public static void main(String[] args) throws InterruptedException {
        myLock lock = new myLock();
       
        new Thread(()->{
            lock.myLock();
            try {
                TimeUnit.SECONDS.sleep(5);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }finally {
                lock.myUnLock();
            }
        },"t1").start();

        TimeUnit.SECONDS.sleep(1);
        new Thread(()->{
            lock.myLock();
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }finally {
                lock.myUnLock();
            }
        },"t2").start();
    }
}
